//
//  TF_LivingVoteScrollViewCell.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/2/19.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

class TF_LivingVoteScrollViewCell: UITableViewCell {

    @objc public var cellWidth:CGFloat = 0
    @objc public var cellHeight:CGFloat = 0

        
    @objc public var view = UIView()
    @objc public var percentage = UIView()//百分比颜色
    @objc public let opLabel = UILabel()
    @objc public let quantity = UILabel() //详情 公布投票结果时显示
    @objc public var model: TFOp?  {
        didSet {
            if ((model) != nil)
            {
                
                let percent =  model!.percent as NSString
                
                
        
                let percentageW = self.cellWidth * ( CGFloat(percent.floatValue) / 100.0)
                
                //选项的百分比
                self.percentage.frame = CGRect(x: 0, y: 0, width: percentageW, height: self.frame.size.height)
                self.quantity.text = model!.opNum + "票" + model!.percent + "%"
          
                
                self.opLabel.textColor = UIColor(red: 20/255.0, green: 23/255.0, blue:26/255.0,alpha:1)
                // A.
                self.opLabel.text = TalkfunSharedTools.asciiBytesToString(inx: self.tag) + model!.op
                
               
                if (model!.selected == false) {
                    self.view.backgroundColor =  UIColor(red: 244/255.0, green: 246/255.0, blue:249/255.0,alpha:1)
              
                    self.view.layer.borderWidth = 0;
                    self.view.layer.cornerRadius = 0;
                    self.opLabel.textColor = UIColor(red: 20/255.0, green: 23/255.0, blue:26/255.0,alpha:1)
                }else{
                    self.view.backgroundColor = UIColor.white
                    
                    self.view.layer.borderColor = UIColor(red: 65/255.0, green: 150/255.0, blue:235/255.0,alpha:1).cgColor
                    
                    self.view.layer.borderWidth = 1
                    self.view.layer.cornerRadius = 4
                    
                    self.opLabel.textColor = UIColor(red: 65/255.0, green: 150/255.0, blue:235/255.0,alpha:1)
                    

                }
                
            }
            
        }
    }
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
     
        self.backgroundColor = UIColor.clear
        self.contentView.addSubview(self.view)
        

        self.view.addSubview(self.percentage)
        self.percentage.backgroundColor = UIColor(red: 213/255.0, green: 234/255.0, blue: 255/255.0,alpha:1)
        

        //名字
        self.view.addSubview(self.opLabel)
        self.opLabel.font = UIFont.PingFang(size: 16)
        
        //百分比

        self.quantity.textAlignment = .right;
        self.quantity.numberOfLines = 0;
        self.opLabel.addSubview(self.quantity)
        self.quantity.font = UIFont.PingFang(size: 13)
        self.quantity.text = "275票  46%";
        self.quantity.textColor = UIColor(red: 20/255.0, green: 23/255.0, blue: 26/255.0,alpha:1)
        
        
    }
    

    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        self.view.frame = CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height - 10)
        self.view.clipsToBounds = true
        self.view.layer.cornerRadius = 4
        self.opLabel.frame = CGRect(x: 20, y: 0, width: self.view.frame.size.width - 20, height: self.view.frame.size.height)
    
        
        self.quantity.frame = CGRect(x: 0, y: 0, width: self.opLabel.frame.size.width - 12, height: self.opLabel.bounds.size.height)
    
        
        
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
